layui.use(['element','table','laytpl'],function () {
    var $ = layui.$,
        table = layui.table,
        layer = layui.layer;
    table.render({
        elem: '#demo'
        ,id:"mytable"
        ,url: '/roundsDeviant/list' //数据接口
        ,page: true //开启分页
        ,limit:15
        ,limits:[15,30,60,100]
        ,response: {
            statusName: 'code' //数据状态的字段名称，默认：code
            ,statusCode: 200 //成功的状态码，默认：0
            ,msgName: 'msg' //状态信息的字段名称，默认：msg
            ,countName: 'total' //数据总数的字段名称，默认：count
            ,dataName: 'rows' //数据列表的字段名称，默认：data
        }
        ,cols: [[ //表头
            {type:'checkbox'}
            ,{title: '序号',type:'numbers'}
            ,{field: 'elderlyName', title: '老人'}
            ,{field: 'elderNo', title: '老人身份证号'}
            ,{field: 'deviantRemark', title: '异常情况'}
           ,
            {
                field: 'createdTime', title: '发生时间', templet: function (r) {
                    return $.dateFormat(new Date(r.createdTime), 'yyyy-MM-dd HH:mm');
                }
            }
            ,{field: 'deviantResult', title: '处理结果'}
            ,{title: '异常来源',templet:function (d) {
                    if (d.status==0){
                        return "护理查房";
                    } else if (d.status==1){
                        return "突发情况";
                    }
                }}
            ,{field: 'cfUser', title: '登记人'}
            ,{title:'操作',toolbar:"#toolbar"}

        ]]
    });

    //工具条
    table.on("tool(test)",function(obj){
        var data = obj.data; //获得当前行数据
        var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
        if("edit" == layEvent){
            location.href = "/roundsDeviant/edit?id=" + data.id+"&buildingId="+data.buildingId;
        }else if("delete" == layEvent){
            location.href = "/roundsDeviant/delete?id=" + data.id;
        }
    });
});